package com.gitee.candy.file;

import lombok.extern.slf4j.Slf4j;
//import net.lingala.zip4j.core.ZipFile;
//import net.lingala.zip4j.model.ZipParameters;
//import net.lingala.zip4j.util.Zip4jConstants;

/**
 * @author suYanLong
 * @version 1.0
 * @date 2024/8/7 14:17
 * @Description 压缩工具类
 */
@Slf4j
public class ZipUtils {

    public static void main(String[] args) {
        String sourceDir = "D:\\workspace\\gitmy\\file";
        String zipFile = "D:\\workspace\\gitmy\\file2\\out.zip";
        String password = "password";
        zip(sourceDir, zipFile, password);
    }

    /**
     * 对文件夹加密压缩
     *
     * @param sourceDir 原文件夹 D:\workspace\gitmy\file
     * @param zipFile   压缩后完整路径 D:\workspace\gitmy\file2\out.zip
     * @param password  密码 password
     * @return
     */
    public static boolean zip(String sourceDir, String zipFile, String password) {
//        try {
//            ZipFile zip = new ZipFile(zipFile);
//            ZipParameters parameters = new ZipParameters();
//            parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
//            parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
//            parameters.setEncryptFiles(true);
//            parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
//            parameters.setPassword(password.toCharArray());
//            zip.addFolder(sourceDir, parameters);
//            System.out.println("Compression and encryption completed successfully.");
//        } catch (Exception e) {
//            log.error("加密压缩发生异常", e);
//            throw new RuntimeException("加密压缩发生异常");
//        }
        return true;
    }

}
